<?php

namespace app\common\model;

use think\Db;
use think\Model;

class ApplyBet extends Model
{

    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'create_time';
    protected $updateTime = false;

    //
    public function getApplyInfoAttr($val){
        return unserialize($val);
    }
    // 今日注册
    public function dayreg($id){
        $date = date('Y-m-d');
        $res = $this->field('count(id) total')
            ->where('user_id',$id)
            ->where([
                'create_time'=>Db::raw("FROM_UNIXTIME(create_time,'%Y-%m-%d') = '{$date}'")
                ])
            ->find();


        if ( !$res ){
            $res = (object)['total'=>0];
        }
        return $res;
    }

    public function user(){
        return $this->belongsTo('User','user_id','id',[],'left')->setEagerlyType(0);
    }

    public function admin(){
        return $this->belongsTo('Admin','admin_id','id',[],'left')->setEagerlyType(0);
    }

    public function apply(){
        return $this->belongsTo('Apply','apply_id','id',[],'left')->setEagerlyType(0);
    }

}